import wepy from 'wepy'

export default class extends wepy.mixin {
  methods = {
    onChange(e) {
      this.secondList = this.categories[e.detail].children
      this.scrollTop = this.scrollTop - 1
    },
    goGoodList(id) {
      wepy.navigateTo({
        url: `/pages/goods_list?cid=${id}`
      })
    }
  }

  data = {
    categories: [],
    activeKey: 0,
    wh: 300,
    secondList: [],
    scrollTop: 0
  }

  onLoad() {
    this.getCategories()
    this.getWh()
  }

  async getCategories() {
    let { data: res } = await wepy.get('/categories')

    if(res.meta.status !== 200) {
      return wepy.baseToast()
    }

    this.categories = res.message
    this.secondList = res.message[0].children
    this.$apply()
  }

  getWh() {
    this.wh = wepy.getSystemInfoSync().windowHeight
  }
}